<?php


namespace app\admin\controller\auth;


use app\admin\controller\AdminController;
use app\admin\service\auth\JobsService;
use app\admin\validate\auth\JobsValidate;
use think\response\Json;

class Jobs extends AdminController
{

    /**
     * 查看岗位列表
     * @return Json
     */
    public function lists()
    {
        return $this->data(JobsService::getList());
    }

    /**
     * 添加岗位
     * @return Json
     */
    public function add()
    {
        $params = (new JobsValidate())->post()->checkParam('add');
        $result = JobsService::add($params);
        if(true === $result) {
            return $this->success([], '添加成功');
        } else {
            return $this->error(JobsService::getError());
        }
    }

    /**
     * 编辑岗位
     * @return Json
     */
    public function edit()
    {
        $params = (new JobsValidate())->post()->checkParam('edit');
        $result = JobsService::edit($params);
        if (true === $result) {
            return $this->success([],'编辑成功');
        } else {
            return $this->error(JobsService::getError());
        }
    }

    /**
     * 删除岗位
     * @return Json
     */
    public function delete()
    {
        $params = (new JobsValidate())->delete()->checkParam('delete');
        $result = JobsService::delete($params);
        if (true === $result) {
            return $this->success([],'删除成功');
        } else {
            return $this->error(JobsService::getError());
        }
    }

    /**
     * 岗位详情
     * @return Json
     */
    public function detail()
    {
        $params = (new JobsValidate())->checkParam('detail');
        $result = JobsService::detail($params);
        return $this->data($result);
    }

    /**
     * 获取岗位
     * @return Json
     */
    public function all()
    {
        $result = JobsService::getAllData();
        return $this->data($result);
    }
}